/* hfunc_jsw1.c
** wcm, 2010.06.04 - 2010.06.06
** ===
*/

#include <stddef.h>
#include <stdint.h>

#include "uchar.h"

#include "hfunc.h"

/* jsw1:
**   designed/enumerated by Julienne Walker, "Eternally Confuzzled"
*/

/* map of 256 random 32-bit unsigned integers in range [0 .. (2^32 - 1)]
** drawn from netbsd /dev/random entropy pool
** (see rand_map.c for generator)
*/ 
static const uint32_t rand_map[] = {
    0xbb4ff5d5,  0x81d0ef50,  0x3be3de34,  0xbe3928ae,  0x81121bb8,  0x89b7a81,  0xd7a475fc,  0x2af22c3f,
    0x4facee74,  0x286c928f,  0xdcec21d8,  0xb0694711,  0x898103b0,  0x2b48f767,  0xd9e0eed4,  0xb2311d0d,
    0x7a49176c,  0xdd6404dc,  0xaf6ffbe1,  0x393860b5,  0x52b24322,  0xcf18bfcc,  0xb95aa116,  0x8e555fa8,
    0x8c0921da,  0xb603c113,  0x2864a218,  0xad9e0cad,  0xafefabd6,  0x32d2dd53,  0x94696c19,  0x80039b0e,
    0xae1d0825,  0xb25772db,  0x55119ef6,  0xae34aec2,  0xaa63568c,  0x6c84809e,  0xa064425e,  0x376ebaad,
    0x983d73d4,  0x4c977e18,  0x464b83a9,  0x5bb3aab2,  0x5cbac837,  0x7b6c431,  0x694664c1,  0x8125164,
    0x4328446a,  0xebe0599,  0x6082f2e3,  0x6a8fb49b,  0xe3e3372c,  0x41cf7f7d,  0x9640101e,  0x6397e4cc,
    0xc9e43e53,  0x9c762476,  0xafaa4ac2,  0xe8ea8950,  0x2de40af4,  0x215ca5af,  0xa2bf5ea5,  0x3431ffad,
    0xf334d67f,  0xcfb96641,  0x68ae8f26,  0x92fb794e,  0xc3a51952,  0x50166b10,  0x59ae3498,  0x47492841,
    0x348558c4,  0x62cc61d3,  0x67f2c511,  0x1e15a35d,  0x3c2e92f9,  0x1ddfe186,  0xf6491c5a,  0xaa268579,
    0x4711eae8,  0xa49247d0,  0xe864f309,  0xfd3a3a2d,  0x51a0c31f,  0xb5e61266,  0xc90c68f0,  0x9ee60a58,
    0xbeaeb5f2,  0x20f09a9e,  0x6fff1a24,  0x3824fc9f,  0xf8f2bbc5,  0x36a59099,  0xd3becf3f,  0xcfb870c,
    0x55f1a507,  0xeae4226b,  0x505babd5,  0x395b52b4,  0xb9684e2,  0xd1988d0a,  0xbb02431e,  0x1847b551,
    0x2458fdfa,  0xb3e0be8f,  0x9e944099,  0x13658807,  0xb44075e0,  0xaa424aef,  0x91cdcb09,  0x9c2ed46d,
    0x584d70f7,  0xc2540faa,  0x5be50aaf,  0x964434c7,  0xabe4d58e,  0xf2d7eb20,  0x1dec0b87,  0x692bc4a3,
    0x7edce51a,  0x3a8c74d8,  0xb88865d0,  0x775d0540,  0xdbadd567,  0x4a9270d0,  0x90198547,  0xb9d29ea5,
    0xef2f4776,  0x62360726,  0x7cd09664,  0x8195b2c4,  0x8b208aa5,  0xe45ec2f3,  0xed5d6200,  0xe1dc50b6,
    0x103d44d4,  0x99e30da7,  0x6607a4d3,  0x3d655e17,  0x336ef939,  0xe57b71b6,  0xbcacdd94,  0x34dd11f9,
    0xab9d8c92,  0xe75a7a75,  0x75c529c4,  0xfad94e11,  0xe23e2e81,  0x1bd78355,  0x76cd07b0,  0x47f83b82,
    0x3214bf39,  0xeae71771,  0xbac4dd0e,  0xcd49ec31,  0x26f5583,  0x2dded4b9,  0x43233cd4,  0x221c3fee,
    0xb0840670,  0x59e082ee,  0xe247931a,  0x3d4d4e6d,  0x27775541,  0x60648f3,  0x3aa022ce,  0x4b61f3ab,
    0xc8750d80,  0xb4f364bf,  0x72647d25,  0xaa8fba85,  0x9593cba9,  0x79b256af,  0x60cbca39,  0x31c1a0a2,
    0x34cdb46d,  0xabfd4ad1,  0x2e13b1ca,  0x8898f84a,  0x5c5830f4,  0xad08e0fc,  0x65d0291f,  0x56f33e36,
    0x21ee7b78,  0x3262f32c,  0xd47aa6e3,  0x1b8275a8,  0x741a0e9b,  0xfd4644c2,  0xc1e32f75,  0xdb4484e8,
    0x4db5b6c6,  0xfefa5770,  0xe36523f9,  0xdd9529c,  0x8796aee4,  0xc8ae4071,  0xcf5e707f,  0x42c98ec4,
    0x12fa0b2c,  0xc38347e5,  0x26d37ef6,  0x808dc121,  0xc7db211f,  0x6341bfd7,  0xa1f44d12,  0x4cb1bc1a,
    0x443072c7,  0x9825174e,  0x4564e7ba,  0xc1fe830e,  0xa513e9ed,  0xd28d951f,  0xe11891e3,  0x86a00934,
    0x69238012,  0x4b84fef9,  0xce211705,  0x98c8e1b6,  0x6f032bd2,  0xccf0db07,  0xda1070d1,  0xbef52500,
    0x2e306192,  0x4dd1045e,  0xac0de9a7,  0x511c48e5,  0x2efa7f0c,  0xcf6babcb,  0x8c8e5eb,  0xc834ad7f,
    0xd2148b94,  0x5a7615de,  0xd51059af,  0x74bf22c0,  0x94c0f221,  0x5d5731d,  0xf61cbc82,  0xd0783eea,
    0xbefc06c3,  0xc07d3837,  0x5ca9329,  0xab69a0c,  0x263ce050,  0xdcfda943,  0x6fa5f0cb,  0xe617c58,
    0x5ee6743,  0xcfd25c55,  0x7411ed61,  0x3089b106,  0x3751cc7,  0xa3b87f3a,  0x478fd37,  0x2fbc3926
};

/* hash function: */
uint32_t
hfunc_jsw1(const uchar_t *key, size_t klen)
{
  uint32_t   h = 1677751U;

  while(klen){
      h = (h << 1 | h >> 31) ^ rand_map[*key];
      ++key; --klen;
  }

  return h;
}

/* eof (hfunc_jsw1.c) */
